Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

p-any

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-any

Wait for any promise to be fulfilled

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
680K
increased by26%
Maintainers
1
Weekly downloads
 
Created

What is p-any?

The p-any package is a utility for handling multiple promises in JavaScript. It returns a promise that is fulfilled when any of the input promises are fulfilled, or rejected if all of the input promises are rejected.

What are p-any's main functionalities?

Basic Usage

This feature demonstrates the basic usage of p-any. It takes an array of promises and returns a promise that resolves as soon as the first promise in the array resolves.

const pAny = require('p-any');
const promise1 = Promise.resolve('First');
const promise2 = new Promise((resolve) => setTimeout(resolve, 100, 'Second'));
const promise3 = new Promise((resolve, reject) => setTimeout(reject, 50, 'Third'));

pAny([promise1, promise2, promise3]).then(value => {
  console.log(value); // 'First'
});

Handling Rejections

This feature demonstrates how p-any handles rejections. If all input promises are rejected, p-any returns an AggregateError.

const pAny = require('p-any');
const promise1 = new Promise((resolve, reject) => setTimeout(reject, 100, 'First'));
const promise2 = new Promise((resolve, reject) => setTimeout(reject, 200, 'Second'));
const promise3 = new Promise((resolve, reject) => setTimeout(reject, 300, 'Third'));

pAny([promise1, promise2, promise3]).catch(error => {
  console.log(error); // AggregateError: All promises were rejected
});

Other packages similar to p-any

Keywords

FAQs

Package last updated on 22 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc